<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<title>Allegro Stuff</title>
	<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- menu -->
	<div id="navmain">
	<ul>
		<li><a href="index.html">Overview</a></li>
		<li><a href="install.html">Installation</a></li>
		<li><a href="config.html">Configurator</a></li>
		<li><a href="animation.html">Animation</a></li>
		<li><a href="framework.html">Framework</a></li>
		<li><a href="tranzam.html">Tutorial</a></li>
	</ul>
	</div>
	<div id="navsub">
	<ul>
		<li><a href="#intro">Overview</a></li>
		<li><a href="#methods">Functions/Data</a><br />
				&nbsp;<a href="#f_core">&gt; Core</a><br />
				&nbsp;<a href="#f_loop">&gt; Game Control<br />
				&nbsp;<a href="#f_helper">&gt; Helper<br />
				&nbsp;<a href="#f_sound">&gt; Audio<br />
				</a></li>
		<li><a href="#f_optimisation">Optimisation</a><br />
		<li><a href="#f_sample">Sample Code</a></li>
		<li><a href="#f_usage">Usage</a></li>
		<li><a href="#f_linking">Config/Animations</a></li>
		<li><a href="#tutorial">Examples</a></li>
		<li><a href="#custom">Custom Loader</a></li>
		<li><a href="#internals">Internals</a></li>
		<li><a href="#f_walk">Code Walkthrough</a><br />
				&nbsp;<a href="#f_cw">&gt; Framework</a><br />
				&nbsp;<a href="#f_wa">&gt; Animation</a></li>
	</ul>
	<p class="smallprint">This menu will stay fixed and look rather fetching with a proper browser like Firefox or Opera. It won't with browsers with dodgy CSS support like Internet explorer</p>
	<p>
	 <a href="http://jigsaw.w3.org/css-validator/">
	  <img style="border:0;width:88px;height:31px"
		   src="http://jigsaw.w3.org/css-validator/images/vcss" 
		   alt="Valid CSS!" />
	 </a>
	</p>
	<p>
      <a href="http://validator.w3.org/check?uri=referer"><img
          src="http://www.w3.org/Icons/valid-xhtml10"
          alt="Valid XHTML 1.0!" height="31" width="88" /></a>
    </p>
<p><a href="http://www.bloggerheads.com/bbc/"><img src="http://www.bloggerheads.com/bbc/bbc.gif" width="90" height="45" alt="Click here to find out why." /></a></p>
	</div>
<!-- menu -->

	<div id="main">
		<a name="intro"></a>
<h1>Framework</h1>
<h2>Overview</h2>
<p>AXL_FRAMS provides a system for creating and running a game without the need for any Allegro initialisation, setup or game loop/timer creation (i.e. you write the game, the framework does the rest), 
contains a series of helper functions/variables to do all the mundane stuff you'd rather not write, handles animation, graphics loading and configuration of allegro and custom values.<br /><br />
If all you require is graphics and animation handling, then do not use this library, instead use AXL_GRANI (Animation library). Similarly if want to control the game yourself and just want to automate the initialisation of Allegro (without the creation of buffers, simplified sound routines, etc) then use AXL_CONCUR (Configurator library). 
If you want to use the facilities of AXL_CONCUR but also want animation/graphic file handling then use AXL_GRANI and AXL_CONCUR.<br/><br />
However, if you wish to write minimal code to initialise AXL_CONCUR and/or AXL_GRANI, want to use additional modules such as the advanced sound control, set up a game/program using paging, triple buffering, or double buffering, then AXL_FRAMS (Framework library) is required. Note that the Framework library 
can be run without the game management (the FPS handler), i.e. you want everything set up but write your own timer/game loop). 

<p>The framework is contained in a single class, Framework. You instantiate a variable of this type and start using its data/functions. What follows is 
a list of the methods and data available to the Framework. The Framework can also handle graphics, animation and configuration values (allegro and custom values). For instructions on using the library, refer afterwards to the 'Usage' section and the tutorials in tests\framework directory - this section is a reference guide.<br /><br />
Instructions for using the Animation and Configurator libraries can be found in their own sections via the menu and are described in brief within this section. When using the Framework to set up and run Animation or Cofigurator there is no need for creating instances of the class, etc. as that is
what the Framework does - it gives you fully instantiated and working Animation and Configurator objects.</p>
Reading the below might not make sense on first reading, but the 'usage' section should make things clearer.
<a name="methods"></a>
<h1>Methods/Data</h1>
<a name="f_core"></a>
<h2>Core</h2>
Although a large amount of functions, realistically you only need to use the first constructor, GetConfiguration()/GetGraphicsLibrary().
<table>
<tr><th>Methods</th><th>	Details</th></tr>
<tr><td>Framework(string config, string animation, bool InitialiseSystem,(*bitmapcreator)(string))</td><td>Construct the Framework. Pass in the name of an XML file or an XML string for animation or config (animation can be blank and signifies you do not want to load any graphics or animations.) The XML file can also be XML data as a string. Refer to the documentation of AnimationLibrary or Configuration for more details. If 'InitialiseSystem' is set (defaults to true) then the constructor fully initialises Allegro, including all the buffers, sound, etc. and leaves you in a graphics state ready to either call the gameloop or to just do your own coding. If not, then you need to call 'InitialiseFramework' afterwards. This is useful to perform any additional tasks before starting the system, e.g. overriding any values a user might change in the XML file.<br/><br />
bitmapcreator is a callback function (defaults to NULL, i.e. not used) for when you wish to use your own function for returning back a bitmap for each of the bitmaps referenced in the animation XML 'bmp_file' attribute. This is useful for custom bitmap loaders other than the default (which will simply assume a bitmap filename that will be loaded). See 'Custom Bitmap Loader' section below.</td></tr>
<tr><td>void InitialiseFramework()</td><td>This function is called automatically by the constructor and should ONLY be called when the 'InitialiseFramework' variable is set to false. </td></tr>
<tr><td>void DestroyFramework()</td><td>The destructor (when you delete your Framework class object) normally calls this. This method destroys all loaded graphics and buffers, free up all memory and leaves the system in text mode. Don't call it unless you have reason for not destroying the Framework class object.</td></tr>
<tr><td>bool RestartSystem(void)</td><td>This function closes all animations/graphics, frees up memory, then reloads the configuration XML and animation (if set) XML files and starts allegro. This function is of use if you wish to change any core allegro values but carry on with the program (e.g. give the user the option to change to triple/paging/double buffering, windowed/fullscreen, etc. This function can only be called if you initialised the framework using a config XML file. Returns false on any errors.</td></tr>
<tr><td>Configuration* GetConfiguration()<br />AnimationLibrary* GetGraphicsLibrary()</td><td>All of the animations and graphics you load are handled by the AXL_GRANI library, and all the configuration values are handled by the AXL_CONCUR library. In order to use all the features of the configurator/animation libraries these two methods return a pointer to the actual library. You can then refer to the Animator/Configurator help file for guidance on their usage. Just remember that you can ignore all the constructors, destructors, etc. as they have already been called. Returns NULL if not set (e.g. no animation object)</td></tr>
<tr><td>BITMAP** GetGraphicBuffers()</td><td>This can be left alone as is not required if you are letting the Framework handle the drawing for you. If you are lettig the Framework initialise the system but you want to use your own game loop this method returns an array of BITMAP* variables, e.g. if you call 'BITMAP* array = F->GetGraphicsBuffers()' then array[0], array[1], array[2] each point to a BITMAP* the size of the screen. If using double buffering, only element 0 is populated, if using paging, elements 0 and 1 are populated and for triple buffering, all elements are populated. NULL if not set.</td></tr>
</table>

<a name="f_loop"></a>
<h2>Game Control</h2>
After initialising the system via the constructor or constructor/InitialiseFramework() you are in a graphics state and everything is set up for you. 
This section contains the data/methods for letting the Framework control your game in a timer based FPS loop.
The FPS timer based loop controls the game speed using a target FPS specified in the XML file/constrcutor (e.g. 60 fps) ). 
The loop is a standard FPS based timer loop you may have seen before. 
There are two parts to any FPS based loop: 
first is the logic - this is where you update your system knowing that it will be called at your FPS (hence ensuring the correct game speed). 
Second is the drawing - this is where you draw your stuff to the drawing buffer.<br /><br />
You write your logic/drawing as if they were called once per frame, where a frame takes up 1/FPS (e.g. 60 FPS means being called 60 times per second).
The Animation object is linked to the Frameworks FPS so all updates are handled automatically (as you can specify animations are updated in milliseconds).
<table>
<tr><th>Methods/Data</th><th>	Details</th></tr>
<tr><td>bool StartGameLoop(		
<br />bool (*logiclogo)(void),
<br />bool (*drawinglogo)(void),
<br />bool (*logicmenu)(void),
<br />bool (*drawingmenu)(void),
<br />bool (*logicgame)(void),
<br />bool (*drawinggame)(void),
<br />bool (*logicexit)(void),
<br />bool (*drawingexit)(void),
<br />bool bUseEscToExit=true
);</td><td>Calling this method invokes the game control. 
This function allows you to pass in up to four logic/drawing pairs of functions (you just pass in the name of the function). 
There are four so that you can separate your code into different parts. 
The parameter names suggest a typical logo, menu, game, exit series of functions. 
These names are just arbitrary, it is in code that you determine which to call. You can pass in NULL to show that you aren't using anything for a pair. 
The first non-null pair from the list is the first logic/drawing functions used in the game loop, i.e. every frame this logic/drawing function you supplied will be called. 
<br /><br />When you need to change to another logic/drawing pair, a function is available and is described below. 
Of course, there is nothing stopping you from simply supplying one logic/drawing pair and doing all the code within. 
This approach will be similar to a typical FPS based loop, but you lose the ability to separate your code and make it easier to manage.
<br /><br />To quit out of the GameLoop (i.e. exit completely and return to the code that invoked StartGameLoop() return a value of true in the drawing/logic. To continue on 
inside the loop, return false.
<br /><br />The final parameter bUseEscToExit defaults to true if not set. If set to true it will automatically return true from the logic function when the ESCape key is pressed, to save it being coded in your logic code.
</td></tr>
<tr><td>ChangeTimerType(TimerType activeTimerType</td><td>When you want to switch the timer loop to another set of functions call this. The parameter can be one of
 GAME_INTRO, GAME_MENU, GAME_GAME, GAME_EXIT. These constants correspond to the function name pairs you specify in StartGameLoop()</td></tr>
<tr><td>SetAutoGameLoopOverride(
								bool (*logic)(void),
								bool (*drawing)(void)
								);</td><td>Sometimes within a logic/drawing function you might want to change to a piece of code but it still part of the current 
								logic/drawing loop. For example during a game you have the option to select pause/options. Instead of writing conditional 
								statements and such in the logic/drawing, simply call this function passing in a new function pointer for the logic/drawing. When you 
								wish to return back to the function that called it, you return 'true' from either function.
</td></tr>
<tr><td>BITMAP* DrawingSurface</td><td>This represents the graphics buffer that you draw to. The system ensures it is the correct one every frame and displays it accordingly (i.e. 
It can be a video, system or memory bitmap and can be show by paging, triple or double buffering. You will need to clear it yourself if need be though.
</td></tr>
<tr><td>int TimerCurrentFPS</td>
<td>This variable holds the FPS the game is currently achieving. For display purposes only. NOTE: This variable is not part of the Framework class, so to use it in your code it needs to be declared as an 'extern', e.g. "extern volatile int TimerCurrentFPS;"</td></tr>

</table>

<a name="f_helper"></a>
<h2>Helper Methods</h2>
<table>
<tr><th>Methods</th><th>	Details</th></tr>
<tr><td>DatLoad
(DATAFILE** dat, string file, bool stop)</td><td>
Load a datafile from file and assign it to dat. 
If stop is passed in as true then the program aborts if it fails to load. 
example:
<p class="code">DATAFILE* myDat;
myAllegro-&gt;DatLoad(&amp;myDat,"file.dat",false);</p></td></tr>
<tr><td>MsgBox(const char* msg1,<br />const char* msg2,<br />BITMAP* bmp=screen,<br />bool waitforspace=true);	</td><td>Outputs a message to either a bitmap if in graphics mode or to the standard output if not. 
Msg1/msg2 are the two lines of text that can be shown, bmp is where to display it and waitforspace will wait for the SPACE key to be pressed. Defaults are as parameters. Be careful when using paging/triple buffers as you may encounter problems using the 'screen' object. Because you can get it to wait for a key press, if you are drawing to a buffer and not the screen, nothing will be shown!</td></tr>
<tr><td>MsgBox(<br />const char* line1,<br />const char* line2, <br />BITMAP* bmp, <br />int w,int h,<br />int transcolour,<br /> int forecolour,<br /> bool transparent,<br />bool waitforspace);</td><td>	If more control is required (such as the colours) then use this function call. These two functions are really there as a backup and normally you will either write your own display code or modify this function in the allegro_core.cpp file. Remember that these functions are used by some functions (e.g. AbortSystem).</td></tr>
<tr><td>WaitForKey(int keyp=KEY_SPACE);</td><td>	Flushes the keyboard and waits for a keypress. Defaults to SPACE if nothing passed in.</td></tr>
<tr><td>AbortSystem(string error)</td><td>This function exits the whole system (freeing all framework resources) and aborting with a message of 'error'. This should only be called on emergencies as it may lead to memory faults such as not freeing up your allocated memory.</td></tr>
</table>

<a name="f_sound"></a>
<h2>Audio Methods</h2>
The Framework uses the more advanced voice controls available with Allegro. These methods are available to make things easy. 
Because the Framework uses the Configurator calling these methods without any proper sound/music devices is fine as full checks are performed. 
<table>
<tr><th>Methods</th><th>	Details</th></tr>
<tr><td>SoundPlayMidi(MIDI* tune, int vol=-1,bool loopflag=false);</td>
<td>Plays a midi tune. Volume can be between 0 and 255 (vol) and can be looped (loopflag). If vol is set to -1 then the default volume is used. 
</td></tr>
<tr><td>SoundStopMidi();</td>
<td>Stop the current midi from playing. Only one can be playing at once.</td></tr>
<tr><td>SoundPlayDigi(DATAFILE* df, int samplenum,int vol=-1, int loopflag=false);</td>
<td>Play a wave file from the passed in datafile, the location of the file within the data file is samplenum parameter. 
Others as midi parameters. Returns the id of the sample so that you can use it with the other Allegro voice functions.
</td></tr>
<tr><td>SoundPlayDigi(SAMPLE* samp, int vol=-1, int loopflag=false);</td>
<td>As above but for a sound derived from a SAMPLE object (e.g. loaded from a file).</td></tr>
<tr><td>SoundStopDigi(int voice,bool force);</td><td>	Stop a sample playing, voice parameter is the id as returned by the playdigi method. The sound will be allowed to finish playing if the parameter force is passed in as false</td></tr>
<tr><td>SoundPurgeDigi(bool killit=false);</td><td>	This clears all sound buffers and deallocates the voice. Only a certain number of voices are allowed at once (defaults to 32, but up to 255). This will loop through all voices and purge any that have stopped and can be released - they are not released automatically.
If using the framework then this is not required as it is called every 5 seconds.</td></tr>
<tr><td>SoundKillDigi();</td><td>	Stops all sounds playing, forcing them to stop immediately.</td></tr>
<tr><td>SoundDigiPos(int voice);</td><td>	Returns the position of a sample.</td></tr>
<tr><td>SoundSetStandardVolumeDigi (int val);
SoundSetStandardVolumeMusic (int val);	</td><td>Set the default volume of midi and wave files.</td></tr>
</table>

<a name="f_optimisation"></a>
<h1>Optimisation</h1>
<ul>
<li>Because the more advanced voice control system is implemented, voices are not automatically de-allocated after they are played. The Framework (when using the game timer loop) will perform this operation every 5 seconds. To change this period, edit the axl.h file and change the '#define TIMER_DIGIPURGETIME' entry.</li>
<li>By default a timer is created to run once per second to store the current FPS. If you have no need to use this (really, it's only use is to see what FPS you are getting) then set OPTIMISE_NO_FPS to 1</li>
</ul>
<a name="f_sample"></a>
<h1>Sample Code</h1>
The framework has two samples. In the tests\framework\example1 directory is the file main.cpp. This is a mainly textual output simply showing how to use the game control system. In the tests\Animation\example3 directory is main.cpp, this shows the Framework using the Animation system and is a complete example on using the Framework system (except the helper functions for sound). 
This example is the same as the example1 and example2 in the same directory but shows how it is done using the Framework. Refer to Animation section for more details.
<br /><br />The code walkthrough section disects the main points of these examples and shows how to use the Framework without using the timer loop.  

<a name="f_usage"></a>
<h1>Usage</h1>
In your source code you need to include the main header file and use the AXL namespace:
<p class="code">#include "axl_framework.h";
using namespace AXL_Projects;</p>

There is one class, Framework. All constructors create a set of base values. 
Normally you will create a Framework by passing in the name of an XML file (or string of XML data) for the config file, (optionally) the name of an 
XML file for the graphics and animation (use "" for no animation file), and whether you want the system to be initialise immediately e.g.

<p class="code">Framework* MyFramework; 
new Framework("config.xml","animations.xml",true);</p>

The defaults (i.e. if not set) are as the function call above. This will create a Configurator object, an Animation Library object (so you can then use animations/graphics and the Configuration file), initialise Allegro 
according to the config.xml file and leave the program in a graphics state. It also creates the drawing buffers according to the config.xml file (e.g. triple buffering, double buffering). 

If you wish to do the Allegro initialisation (e.g. stop people from overwriting width/height) then use the following:
<p class="code">Framework* MyFramework = new Framework("config.xml","animations.xml",false);
Configuration* MyConfig=Framework->GetConfiguration();
MyConfig->CapsGraphics.ScrWidth=800;
MyConfig->CapsGraphics.ScrHeight=600;
MyFramework->InitialiseFramework();</p>
Again, the animation/graphics file can be a blank string to show no graphics are being loaded.

<p>The next thing you'll do is retrieve pointers to your Configuration and Animation objects, e.g.
<p class="code">
//these will probably be globals
Configuration* MyConfig=GetConfiguration();
AnimationLibrary* MyAnimation= GetGraphicsLibrary();
</p>
After this you have everything you need. If you are using the timer based game control they you will call StartGameLoop, which is described in the methods above 
and in the code walkthrough below.

<h1>XML Data</h1>
Instead of using filenames to read from, any of the config or animation parameters can be actual XML data. Refer to the Animation and Configuration section for more details.
<a name="f_linking"></a>
<h1>Using Configurations and Animations</h1>
<h2>Configurations</h2>
To use the configuration file yourself you need a pointer to the Configuration file generated when the Framework was initialised (assuming you 
used XML - otherwise the pointer returned will be NULL).
<p class="code">Configuration* MyConfig=MyFramework->GetConfiguration();</p>
This then gives you full access to all the data and methods in the Configurator class. 
Obviously because the Framework has already created and populated a configuration object and initialised Allegro, you can ignore the Configurator constructors, destructors and 
AllegroStart methods. Similarly in the 'Usage' section you already have the object so you do not need to create a new one. The config filename you pass in to the Framework constructor is
the same filename as the one mentioned in the Configurator constructor. Refer to the 'Configurator' main menu for information on using the Configurator. 
<h2>Animations</h2>
To use the graphics and animations you need a pointer to the Animation Library generated when the Framework was initialised (assuming you passed in a XML 
file for graphics - otherwise the pointer returned will be NULL).
<p class="code">AnimationLibrary* MyAnimation=MyFramework->GetGraphicsLibrary();</p>
Because the Framework has already created and populated the Animation Library, you can ignore the Animation constructor, and the LoadAnimations and DestroyAll methods.
Similarly in the 'Usage' section you already have the object so you do not need to create a new one. The graphics filename you pass in to the Framework constructor is
the same filename as the one mentioned in the Animation Library constructor. Refer to the 'Animations' main menu for information on using the Animation Library. 
<a name="tutorial"></a>
<h1>Examples</h1>
These are found in the tests\framework directory (.\example1 and .\example2). VS2005 and Dev-C++ projects have already been created. If not using either of these two IDE's then follow the installation section to make your own makefile, i.e. include tinyXML library file (or tinyXML source files), the main.cpp in the example directory and axl_framework.cpp. Additionally, example 2 requires axl_animations.cpp and axl_config.cpp.
<ul><li>The first example (example 1) uses the Framework to initialise Allegro, set up the system in whatever mode is in the config (e.g. triple buffering, 32bit, windowed, etc) and control the program using the Framework's timer based system to handle all drawing and logic. Magic!</li>
<li>The second example (example 2) is the biggest of all the examples and uses the Framework to control and run a program with animation. It is the same as the Animation examples 1 and 2, except the Framework handles everything. Only use this after you have read the Configurator help and examples and the Animation help and examples.</li>
</ul>
<a name="internals"></a>
<h1>Internals</h1>
This is not an exhaustive list of what and how the Framework works, for that you need to read the code/help file. This provides a list of what the Constructors, Initialise and Game timer loop does, so that you know what happens within allegro.
<ul>
<li>The constructor passing in the config file and animation file creates an Animation and a Configurator constructor, loading up all animations and graphics, and calls the InitialiseFramework method to initialise Allegro and the Framework.</li>
<li>The InitialiseFramework method (which is called automatically by the main Framework constructor) firstly initialises the sound control system (e.g. the voice array), calls the AllegroStart method of the Configurator to initialise Allegro, it then tries to initialise the buffering system you set up (e.g. triple, paging, double) and falls back to lesser (e.g. if no triple then paging, etc) until it finds a good one (if possible).</li>
<li>StartGameLoop is to run the timer loop to control a game/program. It first sets up the timers to control the game time, the FPS counter and the voice purging system (sound samples need to be updated frequently when using the more advanced Allegro sound control). It then runs a standard FPS based logic/drawing loop calling whatever function pointers (passed into the StartGameLoop) are active.</li>
</ul>
<a name="custom"></a>
<h1>Custom Bitmap Loader</h1>
When graphics are initially loaded they are created using the load_bmp function. After this they are transformed into the correct format (e.g. 
video, system, memory). If you wish to use another file format, e.g. png, or maybe retrieve the graphic from a different location (e.g. a dat file, a custom file system), 
or if you wish to apply some kind of transformation (e.g. rotation, lighting, etc) then you can pass in the name of a function you write to the Animation Library constructor.
This will receive a std::string as the entry name (which is the XML attribute 'bmp_file') and should return a BITMAP* on exit. Or if it fails, passing back NULL will let the system know 
that an error occurred. Animation example 4 shows an example of this pointer, but assuming you called the constructor like this:
<p class="code">Framework* fr=new Framework("config.xml","animations.xml", true, MyBitmapCallback);</p>
And in your code you created MyBitmapCallback as:
<p class="code">BITMAP* MyBitmapCallback(const std::string& filename)
{
	BITMAP* tmp=load_bmp(filename.c_str(),NULL);
	if(tmp)
	{
		BITMAP* newtmp=create_bitmap(tmp->w,tmp->h);
		clear_to_color(newtmp,makecol(255,0,255));
		draw_sprite_v_flip(newtmp,tmp,0,0);
		//bonny lighting!
		//set_trans_blender(255,0,0,255);
		//draw_gouraud_sprite(newtmp,tmp,0,0,255,64,192,32);
		destroy_bitmap(tmp);
		return newtmp;
	}
	else 
		return NULL;
}
</p>
It will simply pass back a flipped (or gouraud shaded) version. You could easily change this to interrogate the string name and appy different things, e.g. simply return back 
a bitmap created using load_bmp for most, but for those ending in ROTATExxx (where xxx is a number), you could rotate the bitmap by xxx degrees. You could then simply pass in
the same bitmap for each graphic item and let the code do the work.<br /><br />
NOTE: the callback will only be called for graphics that are actually loaded. i.e. it will not be called for subbitmaps (those with the 'issheetgraphic' set to 1) or those that are 
duplicates (have the same bmp_file entry). Also note, that you should ALWAYS return back a memory bitmap as the transformation to the correct type will be made by the system.

<a name="f_walk"></a>
<a name="f_cw"></a>
<h1>Code Walkthrough</h1>
<h2>Framework with Game Timer Loop only</h2>
We will now walk through the code in tests\framework\example1\main.cpp<br /><br />
This example uses only the Framework with no animations and no interaction with the Configuration object (other than using it to initialise Allegro).<br /><br />
The first 36 lines are simply the header file, namespace (as mentioned earlier) and the declarations for the functions used (as we are not using a separate header file).
<br /><br />The Framework is initialised as per the Usage section: 	GameFramework=new Framework("config.xml","");
<br /><br />Note that we have not passed in any graphics file. Next follows some error checking (this was omitted in the usage section simply to make the code easier to read):
<p class="code">	if(Configuration::GlobalErrorString!="")
	{
		delete GameFramework;
		allegro_message(Configuration::GlobalErrorString.c_str());
	}
	else
	{
</p>
Throughout the framework, configuration, animation the GlobalErrorString is only populated in case of serious errors. So this code deletes the framework object and exits if there was an error.
<p class="code">		GameStartup();</p>This calls a function created later in the code. Reading this function you can see that all it is doing is initialising a few variables and clearing the current drawing buffer.
<p class="code">		if( !GameFramework->StartGameLoop(
			LogicIntro,DrawingIntro,
			LogicMenu,DrawingMenu,
			LogicGame,DrawingGame,
			LogicExit,DrawingExit,true) 
		) 
		{
			//GameFramework->DestroyFramework();
			delete GameFramework;
			allegro_message("Failed to run game loop. Check config.log");
		}
		else 
		{
</p>
Next the timer based loop is called. If it fails then the framework is deleted. As you can see every function pair is populated. This means that the timer 
loop once it starts will run at the FPS in the config file and will initially call 'LogicIntro' and 'DrawingIntro'.

The code for 'LogicIntro' is as follows:
<p class="code">bool LogicIntro()
{
	if(key[KEY_1])
	{
		GameFramework->ChangeTimerType(GAME_MENU);
		position+=10;
	}
	return false;
}</p>
If nothing happens during this loop then false is returned signifying the game should not exit. If the '1' key is pressed then 
the timer loop function is changed to whatever was set in the 'GAME_MENU'. In this case, it is 'LogicMenu' and 'DrawingMenu'. So on the next 
loop the timer will call these functions. 
<br /><br />Following on you can see that each logic function chains the code along to another piece. During the MENU section, instead of pressing '2' as 
shown, pressing X will restart the system. During the GAME section, the 'overload' method is called to show what happens when you set a temporary logic/drawing pair. On exiting the override, the GAME code continues as normally. 
Finally, during the last bit of code, EXIT, the function returns true to signify that the game loop should end. Control then passed back 
to the main() function which continues on with:
<p class="code">			delete GameFramework;
			allegro_message("Termination of Program ok. Check config.log");
</p>
Which deletes the framework. This deletion clears up memory and exits a graphics state.
<a name="f_wa"></a>
<h2>Framework using Animations</h2>
This walkthrough relates to tests\animation\example3\main.cpp and assumes you have read and understood the previous code walkthrough. 
It also does not mention the animation code in detail as this is fully described in the Animation section. 
The code is the example as shown in tests\animation\example1 and exampl2. The difference being example3 uses the Framework to control the system. 
The code within main() is the same as the previous example. Indeed if using the Framework and the timer game loop then the code will usually be the same as this. 
<p class="code">GameFramework=new Framework("config.xml","animations.xml");</p>
This uses an animation this time. So on initialisation of the Framework, all graphics and animations are loaded too.
<p class="code">SetupGame();</p>This initialises and retrieves the configuration and animation/graphics pointers, i.e.
<p class="code">	GameLibrary=GameFramework->GetGraphicsLibrary();
	GameConfiguration=GameFramework->GetConfiguration();
</p>
Using the animation object it then retrieves the first animation, ufo, 
<p class="code">	MainAnimation=new Animation(GameLibrary,"ufo");
</p>
After this, the game timer loop is invoked:
<p class="code">		if( !GameFramework->StartGameLoop(
				NULL,NULL,
				NULL,NULL,
				LogicGame,DrawingGame,
				NULL,NULL,true) ) 
</p>
As you can see only one function pair is called, as there is no need for any other as it is a simple program. The 'ChangeTimerType' method has not been called at any point. 
This is because the Framework will use the first non-null function pointer it finds as it's first calling point. The LogicGame is just a copy/paste from the code in the previous animation examples and 
processes key presses. The drawing code, similarly, is the same, except all drawing is sent to the GameFramework->DrawingSurface object.

</div>
</body>
</html>
